<!-- 关联人员 -->
<template>
    <div id='' class='system_set_form'>
        <Input search enter-button clearable v-model="value" placeholder="请输入关键字进行过滤" @on-search="selectTree" @on-clear="selectClear"></Input>
        <Tree disableCheckbox ref="treeRef" :data="treeList" show-checkbox></Tree>
    </div>
</template>
<script>
export default {
    name: '',
    props: [''],
    data() {
        return {
            value: '',
            treeList: [],
            oldTreeData: [],
            newTreeData: [],
        };
    },
    components: {},
    computed: {},
    beforeMount() { },
    mounted() { },
    methods: {
        // 树数据
        setTreeList(list) {
            this.oldTreeData = this.treeList = JSON.parse(JSON.stringify(list));
        },


        // 树查询
        selectTree(data) {
            this.newTreeData = [];
            this.foundTree(data, this.oldTreeData);
            this.treeList = this.newTreeData;
        },

        foundTree(value, list) {

            list.forEach(item => {
                if (item.title.includes(value)) {
                    this.newTreeData.push(item)
                } else {
                    if (item.children && item.children.length > 0) {
                        this.foundTree(value, item.children)
                    }
                }
            })
        },

        // 获取选中项
        getCheckList() {
            let arr = [];
            this.getChecked(arr,this.oldTreeData);
            // this.checkList.forEach(item => {
            //     if (item.children && item.children.length == 0) {
            //         arr.push(item.id)
            //     }
            // });
            return arr;

            // let arr = [];
            // this.$refs.treeRef.getSelectedNodes().forEach(item => {
            //     arr.push(item.id)
            // });
            // return arr;
        },

        getChecked(arr,list) {
            list.forEach(item => {
                if (item.children && item.children.length > 0) {
                    this.getChecked(arr,item.children);
                }else{
                    if(item.checked == true && item.type == 1){
                        arr.push(item.id)
                    }
                }
            })
        },

        // 清空搜索内容
        selectClear() {
            this.selectTree('')
        }
    },
    watch: {}
}
</script>
<style lang='less' scoped>
</style>
